package graph.day03;

import java.util.Scanner;

public class Kama_103 {

    static int[][] direction = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};

    static int[][] graph;

    static boolean[][][] visited;

    static boolean[][][] reached;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        graph = new int[n][m];
        visited = new boolean[n][m][3];
        reached = new boolean[n][m][3];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                graph[i][j] = sc.nextInt();
            }
        }
        for (int i = 0; i < n; i++) {
            dfs(i, 0, 1);
        }
        for (int j = 0; j < m; j++) {
            dfs(0, j, 1);
        }
        for (int i = 0; i < n; i++) {
            dfs(i, m - 1, 2);
        }
        for (int j = 0; j < m; j++) {
            dfs(n - 1, j, 2);
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (reached[i][j][1] && reached[i][j][2]) {
                    System.out.println(i + " " + j);
                }
            }
        }
    }

    private static void dfs(int i, int j, int mark) {
        reached[i][j][mark] = true;
        visited[i][j][mark] = true;
        for (int[] dir : direction) {
            int x = i + dir[0];
            int y = j + dir[1];
            if (x < 0 || y < 0 || x >= graph.length || y >= graph[0].length) continue;
            if (graph[i][j] <= graph[x][y] && !visited[x][y][mark]) {
                dfs(x, y, mark);
            }
        }
    }
}
